package day20180129.designMode.seven_builder;



/**
 * Created by 14394 on 2018/1/29.
 */


/*
*    优点： 建造者独立，易扩展
*          便于控制细节风险
*     使用场景：  需要生成的对象具有复杂的内部结构
*                需要生成的对象内部属性本身相互依赖
*                常与stringBuffer连用
*         与工厂模式的区别：更加关注与零件装配的顺序
* */
public class Test {
    public static void main(String[] args) {
        if (args.length!=1){
            usage();
            System.exit(0);
        }

        if (args[0].equals("plain")){
            TextBuilder textBuilder= new TextBuilder();
            Director director = new Director(textBuilder);

            director.construct();

            String result = textBuilder.getResult();
            System.out.println(result);
        }else if (args[0].equals("html")){
            HTMLBuilder htmlBuilder = new HTMLBuilder();
            Director director = new Director(htmlBuilder);

            director .construct();
            String fileName = htmlBuilder.getResult();
            System.out.println(fileName + "文件编写完成。");
        }else {
            usage();
            System.exit(0);
        }
    }

    public static void usage(){
        System.out.println("Usage: java Main plain   编写纯文本文档");
        System.out.println("Usage: java Main html    编写HTML文档");


        TextBuilder textBuilder= new TextBuilder();
        Director director = new Director(textBuilder);

        director.construct();

        String result = textBuilder.getResult();
        System.out.println(result);
    }
}
